#import "AppDelegate.h"

#import "EAGLView.h"

#import "GameController.h"

#include "TextureCache.h"

#include "Configuration.h"

#include "DemoScene.h"

@implementation AppDelegate

@synthesize window = _window;

- ( BOOL)application:( UIApplication*) application didFinishLaunchingWithOptions:( NSDictionary*) launchOptions
{
    CGRect screenBounds = [[UIScreen mainScreen] bounds];

    self.window = [[UIWindow alloc] initWithFrame:screenBounds];
    
    self.window.backgroundColor = [UIColor blackColor];
    
    self.window.rootViewController = ( UIViewController*)Meteor::GameController::Instance().ViewController();
    
    std::vector<UIInterfaceOrientation> orientations;
    
    orientations.push_back( UIInterfaceOrientationLandscapeLeft);
    
    orientations.push_back( UIInterfaceOrientationLandscapeRight);
    
    orientations.push_back( UIInterfaceOrientationPortrait);
    
    orientations.push_back( UIInterfaceOrientationPortraitUpsideDown);
    
    EAGLView* glView = [(EAGLViewController*)Meteor::GameController::Instance().ViewController() defaultViewForOrientations:orientations];
        
    glView.opaque = NO;
    
    [self.window addSubview:glView];
    
    [glView startRendering];
    
    DemoScene* demo = new DemoScene();
    
    Meteor::GameController::Instance().RunScene( demo);
    
    [self.window makeKeyAndVisible];
    
    return YES;
}

// -----------------------------------------------------------------------------

- ( void)dealloc
{
    [self.window release];
    
    [super dealloc];
}

// -----------------------------------------------------------------------------

- ( void)applicationWillResignActive:( UIApplication*) application
{
}

// -----------------------------------------------------------------------------

- ( void)applicationDidEnterBackground:( UIApplication*) application
{
}

// -----------------------------------------------------------------------------

- ( void)applicationWillEnterForeground:( UIApplication*) application
{
}

// -----------------------------------------------------------------------------

- ( void)applicationDidBecomeActive:( UIApplication*) application
{
}

// -----------------------------------------------------------------------------

- ( void)applicationWillTerminate:( UIApplication*) application
{
}

@end
